<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="tr" xml:lang="tr">
<head>
    <title>Docume</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>

<?php

    $db_dir = "../_db/";

    require_once ('../config/config.php');
    require_once ('../lib/vezir.php');

    $Vezir = new Vezir($CF['Db']);

    if (isset($_GET["file"])) {
        $file_ = $db_dir.$_GET["file"];
        if (file_exists($file_)){

            require_once ("../lib/xml.php");
            require_once ("../lib/sql.php");

            $xml=get_xml($file_);

            $sql = new SQLBuilder($xml);

            # get the table name form address bar..
            if (isset($_GET["table"])) $table=$_GET["table"];else $table="all";

            echo "<pre>";
            print_r( $sql->GetSQL($table));
            echo "</pre>";
            
            if (isset($_GET['execute'])){
                if ($_GET['execute']=='yes')
                    if ($sql->ExecSQL($Vezir))
                        echo "Success.";
                    else
                        echo "Failed.";
            }
            else
                echo "<br/><strong>Want to execute? <a href='?file={$_GET["file"]}&execute=yes'>Yes</a></strong>";
        }
    }

    else
        # file list..
        if ($handle = opendir("../_db/")){
            while (false !== ($file=readdir($handle)))
            if (is($file,'xml'))
                echo "<a href='{$PHP_SELF}?file=$file'>$file</a><br/> ";
            else
                echo "$file<br/>";
        }

    # check file
    function is($f,$p) {
        return $p==substr($f,strlen($f)-strlen($p),strlen($p));
    }

?>

</body>
</html>
